<?php include "./install/view/header.inc.htm"; ?>

<h3>二、数据库配置</h3>

<form id="form" action="index.php?0=step2" method="post">
	
	<div class="panel_body">
		<dl class="row form">
			<dt class="right col-2">数据库类型：</dt>
			<dd class="col-8">
				<label><input type="radio" name="type" value="mysql" <?php echo ($mysql_support ? ' checked' : ' disabled'); ?> />mysql</label>
				<label><input type="radio" name="type" value="pdo_mysql" <?php echo ($pdo_mysql_support ? ' checked' : ' disabled'); ?> />pdo_mysql</label>
			</dd>
		</dl>
		<dl class="row form">
		        <dt class="col-2 right">数据库服务器：</dt>
		        <dd class="col-8"><input type="text" name="host" value="<?php echo (IN_SAE ? SAE_MYSQL_HOST_M : '127.0.0.1'); ?>"></dd>
		        
		        <dt class="col-2 right">数据库名：</dt>
		        <dd class="col-8"><input type="text" name="name" value="<?php echo (IN_SAE ? SAE_MYSQL_DB : 'xiuno'); ?>"></dd>
		        
		        <dt class="col-2 right">数据库用户名：</dt>
		        <dd class="col-8"><input type="text" name="user" value="<?php echo (IN_SAE ? SAE_MYSQL_USER : 'root'); ?>"></dd>
		        
		        <dt class="right col-2">数据库密码：</dt>
		        <dd class="col-8"><input type="text" name="pass" value="<?php echo (IN_SAE ? SAE_MYSQL_PASS : 'root'); ?>"></dd>
		        
		        <dt class="right col-2">是否安装测试数据：</dt>
		        <dd class="col-8"><label><input type="checkbox" name="test_data" value="1">是</label></dd>
		</dl>
		<h3>管理员信息</h3>
		<dl class="row form">
			<dt class="right col-2">管理员邮箱：</dt>
			<dd class="col-8"><input type="text" name="adminemail" value="admin@admin.com"></dd>
			<dt class="right col-2">管理员账户：</dt>
			<dd class="col-8"><input type="text" name="adminuser" value="admin"></dd>
			<dt class="right col-2">管理员密码：</dt>
			<dd class="col-8"><input type="text" name="adminpass" value=""></dd>
		</dl>
	</div>
	<div class="center margin">
		<button type="button" class="blue big" onclick="history.back();">上一步</button>
		<button type="submit" class="blue big" id="submit" loading-text="正在安装..." >下一步</button>
	</div>
</form>
<?php include "./install/view/footer.inc.htm"; ?>

<script>

// 字段检测
var jform = $('#form');
var jsubmit = $('#submit');
jform.on('submit', function() {
	jsubmit.button('loading');
	var type = jform.find('input[name="type"]').checked();
	var postdata = jform.serialize() + '&type='+type;
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			window.location = 'index.php?0=step3';
		} else if(code == 1) {
			jform.find('input[name="host"]').popover(message).focus();
		} else if(code == 2) {
			jform.find('input[name="name"]').popover(message).focus();
		} else if(code == 3) {
			jform.find('input[name="user"]').popover(message).focus();
		} else if(code == 4) {
			jform.find('input[name="pass"]').popover(message).focus();
		} else if(code == 8) {
			jform.find('input[name="adminpass"]').popover(message).focus();
		} else if(code == 5) {
			$.confirm('检测到您已经安装过了，强制安装会清空原有数据，您还继续吗？', function() {
				jform.attr('action', jform.attr('action')+'&force=1');
				jform.trigger('submit');	
			});
		} else {
			$.alert(message);
		}
		jsubmit.button('reset');
	});
	
	return false;
});

</script>

